// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CImplItemset.
//   $Id$



#pragma once
#include "nodesetBinding.h"
#include <list>

typedef std::list<CComBSTR> CComBSTRList;

class CImplCopy;
class CXFormsElementItemset;
class CImplContextualValue;
class CResolvedItem;
class CImplAlert;

class CImplItemset 
	: public CImplNodesetBinding
	, public ISelectionChild
	, public IItemWithAlert
{
	friend class CXFormsParseItemset;
public:

//	virtual bool checkValue(BSTR const sVal);
//	virtual void getFirstValue(BSTR * psVal);
	virtual HRESULT draw(BSTR const sDrawInside);
	virtual CImplSelection * GetOwnerSelection();
	CImplItemset(CXFormsElementItemset* pXFEl);
	CImplItemset();
	virtual ~CImplItemset();
	virtual HRESULT detachCaption();
	virtual HRESULT onAlertValueChange(BSTR /*sCaption*/) { return S_FALSE; }
	virtual HRESULT detachAlert(void);

	virtual HRESULT init(CImpl* pParent);
	virtual HRESULT refresh();

	//These two are mutually exclusive, consider making a union.
	//  However, a union may be more hungry, as I would need to store
	//	a value to test what is in my union. (like VARIANT.vt)
	CImplContextualValue * m_pValue;
	CImplCopy  * m_pCopy;
	virtual void SetSelectionIndex(long lIndex);
	virtual void select(const long lIndex);
	virtual void deselect();
	virtual void selectFrom(CList<VARIANT, VARIANT> &lstNodes, CStringW & sList);
	virtual HRESULT formControlInitialize();
	virtual HRESULT redraw(){return refresh();};
private:
//TODO: remove - these are not all properties of itemset
	CImplAlert* m_pAlert;
	CImplContextualValue * m_pCaption;
	bool m_bRefreshing;

	void CreateResolvedCounterpart();
	//array of items, to which the nodeset resolves.
	//NB: this class does not own the items' memory.
	CTypedPtrArray<CPtrArray,CResolvedItem*> m_arrItems;
	//ResolvedItemList belonging to the parent.
	//	note that this class does not own it.
	CResolvedItemList * m_pParentList;
	long m_lIx;
	void GetValueAt(long  lIndex, BSTR *sValue);
	void GetCopyNodeAt(long  lIndex,IXMLDOMNode ** ppCopyNode);
	bool m_bSelected;
	bool m_bDoneOnce;

	CComBSTRList * m_pLastLabelList;


public:
	HRESULT onvaluechanged(void);
};
